/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.techopropio.bfh.persistence;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import com.techopropio.bfh.model.Bean;
import com.techopropio.bfh.model.Usuario;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 *
 * @author Home
 */
public class UsuarioDao implements DAO{
    Usuario usuario = null;
    
    @Override
    public int insert(Bean bean) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int update(Bean bean, String condicion) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

   
    public Bean findUsuario(String loginName, String password) throws SQLException {
        Connection conn = Conexion.obtenerConnexion();
        PreparedStatement ps =   (PreparedStatement) conn.prepareStatement("select *  from usuario where codigo=? "+ 
                     " and password = ? " );
            ps.setString(1, loginName);
            ps.setString(2, password);
            
            ResultSet rs=ps.executeQuery();
            // Se realiza la consulta. Los resultados se guardan en el 
            // ResultSet rs
//            ResultSet rs = s.executeQuery ("select *  from usuario where codigo="+ codigo+
//                     " and password="+password+ " and cargo="+tipo );
            //ResultSet rs = 
            
            if(rs.next()){
                usuario = new Usuario();
                usuario.setLoginName(rs.getString("dni"));
                usuario.setRol(rs.getString("tipo"));
                usuario.setIdUsuario(rs.getInt("idUsuario"));
            }else{
                System.out.println("No hay");
            }
            conn.close();
            return  usuario;
        
    }

    @Override
    public List<Bean> select(String condicion) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int delete(String condicion) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Bean find(String condicion) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
